package item;

public class Item {
	
	public enum Type
	{
		CD,
		DVD;
		
		static private String[] typeStrings = {
				"CD",
				"DVD",
		};
		
		static public Type valueOfString(String typeString)
		{
			for(Type curType : values())
			{
				String curTypeString = typeStrings[curType.ordinal()]; 
				if(curTypeString.equals(typeString.toUpperCase()))
				{
					return curType;
				}				
			}
			
			return null;
		}
		
		public String toString()
		{
			return typeStrings[ordinal()];
		}
	}
	
	public enum Category
	{
		ROCK,
		POP,
		RAP,
		COUNTRY,
		CLASSICAL,
		NEW_AGE,
		INSTRUMENTAL;
		
		static private String[] categoryStrings = {
				"ROCK",
				"POP",
				"RAP",
				"COUNTRY",
				"CLASSICAL",
				"NEW AGE",
				"INSTRUMENTAL",
		};
		
		static public Category valueOfString(String categoryString)
		{
			for(Category curCat : values())
			{
				String curCatString = categoryStrings[curCat.ordinal()]; 
				if(curCatString.equals(categoryString.toUpperCase()))
				{
					return curCat;
				}				
			}
			
			return null;
		}
		
		public String toString()
		{
			return categoryStrings[ordinal()];
		}
	}
	
	protected String	upc;
	protected String 	title;
	protected Type 		type;
	protected Category	category;
	protected String	company;
	protected int		year;
	protected float		sellPrice;
	
	public Item(String upc, String title, Type type, Category category, String company, int year, float sellPrice) 
	{
		this.upc = upc;
		this.title = title;
		this.type = type;
		this.category = category;
		this.company = company;
		this.year = year;
		this.sellPrice = sellPrice;
	}
	
	public Item(String upc, String title, String type, String category, String company, int year, float sellPrice) 
	{
		this.upc = upc;
		this.title = title;
		this.type = Type.valueOfString(type);
		this.category = Category.valueOfString(category);
		this.company = company;
		this.year = year;
		this.sellPrice = sellPrice;
	}
	
	public Item(Item other)
	{
		this(other.getUpc(), other.getTitle(), other.getType(), other.getCategory(), other.getCompany(), other.getYear(), other.getSellPrice());
	}
	
	public String getUpc() {
		return upc;
	}
	
	public String getTitle() {
		return title;
	}
	
	public Type getType() {
		return type;
	}
	
	public Category getCategory() {
		return category;
	}
	
	public String getCompany() {
		return company;
	}
	
	public int getYear() {
		return year;
	}
	
	public float getSellPrice() {
		return sellPrice;
	}
	
	public void setSellPrice(float newSellPrice)
	{
		sellPrice = newSellPrice;
	}
	
	@Override
	public boolean equals(Object other)
	{
		if( this == other )
		{
			return true;
		}
		
		if( !(other instanceof Item) )
		{
			return false;
		}
		
		Item otherItem = (Item) other;
		
		return otherItem.getUpc().equals(this.upc);		
	}
	
	@Override
	public int hashCode()
	{
		return upc.hashCode();
	}
}

